class Command {
  execute() {}
}

class Light {
  turnOn() {
    console.log('Light turned on');
  }

  turnOff() {
    console.log('Light turned off');
  }
}

class TurnOnLightCommand extends Command {
  constructor(light) {
    super();
    this.light = light;
  }

  execute() {
    this.light.turnOn();
  }
}

class TurnOffLightCommand extends Command {
  constructor(light) {
    super();
    this.light = light;
  }

  execute() {
    this.light.turnOff();
  }
}

const light = new Light();
const turnOnCommand = new TurnOnLightCommand(light);
const turnOffCommand = new TurnOffLightCommand(light);

turnOnCommand.execute(); // 输出：Light turned on
turnOffCommand.execute(); // 输出：Light turned off
